<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-商品列表</title>
	<link rel="stylesheet" type="text/css" href="${path}/static/front/css/reset.css">
	<link rel="stylesheet" type="text/css" href="${path}/static/front/css/main.css">
</head>
<body>
	<div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到天天生鲜!</div>
			<c:if test="${user!=null}">
			<div class="fr">
				<div class="user_link fl">
					欢迎您：<em style="color:#CC0000;">${user.username}</em>
					<span>|</span>
					<a href="user_center_info.html">用户中心</a>
					<span>|</span>
					<a href="cart.html">我的购物车</a>
					<span>|</span>
					<a href="${path}/order/getUserCenterOrder.shtml">我的订单</a>
				</div>
			</div>
			</c:if>
			<c:if test="${user==null}">
				<div class="fr">
					<div class="login_btn fl">
						<a href="javascript:void(0);" onclick="loginSubmit()">登录</a>
						<span>|</span>
						<a href="${path}/register.jsp">注册</a>
					</div>
					<div class="user_link fl">
						<span>|</span>
						<a href="user_center_info.html">用户中心</a>
						<span>|</span>
						<a href="cart.html">我的购物车</a>
						<span>|</span>
						<a href="user_center_order.html">我的订单</a>
					</div>
			</div>
			</c:if>
		</div>		
	</div>

	<div class="search_bar clearfix">
		<a href="${path}/index.shtml" class="logo fl"><img src="${path}/static/front/images/logo.png"></a>
		<div class="search_con fl">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>
		<div class="guest_cart fr">
			<a href="#" class="cart_name fl">我的购物车</a>
			<div class="goods_count fl">1</div>
		</div>
	</div>

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="#" class="fruit">新鲜水果</a></li>
					<li><a href="#" class="seafood">海鲜水产</a></li>
					<li><a href="#" class="meet">猪牛羊肉</a></li>
					<li><a href="#" class="egg">禽类蛋品</a></li>
					<li><a href="#" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="#" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">新鲜水果</a>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					<li>
						<a href="#"><img src="${path}/static/front/images/goods/goods001.jpg"></a>
						<h4><a href="#">进口柠檬</a></h4>
						<div class="prize">￥3.90</div>
					</li>
					<li>
						<a href="#"><img src="${path}/static/front/images/goods/goods002.jpg"></a>
						<h4><a href="#">玫瑰香葡萄</a></h4>
						<div class="prize">￥16.80</div>
					</li>
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<div class="sort_bar">
				<a href="#" class="active">默认</a>
				<a href="#">价格</a>
				<a href="#">人气</a>
			</div>

			<ul class="goods_type_list clearfix">
				<c:forEach items="${productList}" var="product">
					<li>
						<a href="${path}/product/getProductDetailPage.shtml?productId=${product.id}"><img src="/pic/${product.mainImage}"></a>
						<h4><a href="${path}/product/getProductDetailPage.shtml?productId=${product.id}">${product.name}</a></h4>
						<div class="operate">
							<span class="prize">${product.price}</span>
							<span class="unit">${product.price}/500g</span>
							<a href="#" class="add_goods" title="加入购物车"></a>
						</div>
					</li>
				</c:forEach>
			</ul>

			<div class="pagenation">
				<a href="#"><上一页</a>
				<a href="#" class="active">1</a>
				<a href="#">2</a>
				<a href="#">3</a>
				<a href="#">4</a>
				<a href="#">5</a>
				<a href="#">下一页></a>
			</div>
		</div>
	</div>

	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	
	<div id="loginForm" class="login_form fr" style="display:none">
		<div class="login_title clearfix">
			<h1>用户登录</h1>
			<a href="${path}/register.jsp">立即注册</a>
		</div>
		<div class="form_input">
			<form id="login_form" onsubmit="return false">
				<input type="text" name="username" id="username" class="name_input" placeholder="请输入用户名">
				<div class="user_error">输入错误</div>
				<input type="password" name="password" id="password" class="pass_input" placeholder="请输入密码">
				<div class="pwd_error">输入错误</div>
				<div class="more_input clearfix">
					<input type="checkbox" name="">
					<label>记住用户名</label>
					<a href="#">忘记密码</a>
				</div>
				<input type="submit" onclick="submitForm()" name="" value="登录" class="input_submit">
			</form>
		</div>
	</div>
	
	<script src="${path}/static/lib/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/lib/myUtil.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function loginSubmit(){
			layer.open({
				type: 1,
				title: "请先登录",
//					offset: "50px",
				skin: 'layui-layer-molv',
				area: ["400px", "450px"],
				content: $("#loginForm")
			});
		}
		
		function submitForm(){
			// 1、	验证用户名
			// 1.1	用户名不能为空
			// 1.2	格式是否合法：4-8位数字或字母
			var username = $("#username").val();
			var password = $("#password").val();
			// 1.1	用户名不能为空
			if (myUtil.isEmpty(username)) {
				mylayer.errorMsg("用户名不能为空");
				return;
			}
			// 1.2	格式是否合法：4-8位数字或字母
			var pattern = /^[0-9a-zA-Z]{4,8}$/;
			// if (!pattern.test(name)) {
			if (pattern.test(username) == false) {
				mylayer.errorMsg("用户名格式非法，4-8位数字或字母");
				return;
			}
			// 2、密码验证
			// 2.1	用户名不能为空
			// 2.2	格式是否合法
			
			// 2.1	用户名不能为空
			if (myUtil.isEmpty(password)) {
				mylayer.errorMsg("密码不能为空");
				return;
			}
			// 2.2	格式是否合法
			var pattern = /^[0-9a-zA-Z]{3}$/;
			// if (!pattern.test(password)) {
			if (pattern.test(password) == false) {
				mylayer.errorMsg("密码格式非法，3位数字或字母");
				return;
			}
			
			$.ajax({
				url: "${path}/user/login.shtml",
				data: $("#login_form").serialize(),
				type: "post",
				dataType: "json",
				success: function(jsonObj) {
					if (jsonObj.code == myUtil.SUCCESS) {
						mylayer.successMsg(jsonObj.msg);
						//当你在iframe页面关闭自身时
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						
 						setTimeout(function(){
 							parent.layer.close(index); //再执行关闭 
 							// 刷新父页面
 							window.parent.location.reload();
 						},1000);
							
					} else {
						mylayer.errorMsg(jsonObj.msg);
					}
			}
			});
		}
	</script>
	
</body>
</html>